package com.thrd.taiexhibition.activity;

import android.view.View;
import android.widget.TextView;

import com.alibaba.android.arouter.facade.annotation.Autowired;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.thrd.basicframework.ui.webview.JieWebView;
import com.thrd.taiexhibition.R;
import com.thrd.taiexhibition.base.BackTitleActivity;
import com.thrd.taiexhibition.bean.BeanRichText;
import com.thrd.taiexhibition.presener.RichTextPresener;
import com.thrd.taiexhibition.utils.JumpUtils;
import com.thrd.taiexhibition.view.RichTextView;

/**
 * @author: ${唐杰}
 * @date: 2021/4/6
 */
@Route(path = JumpUtils.RICH_TEXT,group = "app")
public class RichTextActivity extends BackTitleActivity implements RichTextView {
   private JieWebView mJieWebView;
    private RichTextPresener mRichTextPresener;
    @Autowired(name=JumpUtils.RICH_ID)
    long articleId;
    private TextView mTitleName;

    @Override
    protected int getLayout() {
        return R.layout.activity_richtext;
    }

    @Override
    protected void initView() {
        mJieWebView = (JieWebView) findViewById(R.id.cnsw_webview);
        mTitleName = (TextView) findViewById(R.id.tv_title_name);
    }

    @Override
    protected void initData() {
        mRichTextPresener = new RichTextPresener(this);
        mRichTextPresener.getRichTextData(articleId);
    }

    @Override
    protected void initEvent() {

    }


    @Override
    protected void onDestroy() {
        super.onDestroy();
        setContentView(new View(this));
        if(mJieWebView!=null){
            mJieWebView.stopLoading();
            mJieWebView.getSettings().setJavaScriptEnabled(false);
            mJieWebView.clearHistory();
            mJieWebView.clearView();
            mJieWebView.removeAllViews();
            mJieWebView.destroy();
            mJieWebView=null;
            System.gc();
        }

    }

    @Override
    public void onError(String error, int type) {

    }

    @Override
    public void onSuccess(BeanRichText mBeanRichText) {
        mTitleName.setText(mBeanRichText.getArticleTitle());
        mJieWebView.loadDataWithBaseURL(mBeanRichText.getRichText());
    }
}
